<template>
  <div class="big-box">
    <div class="big_top">
      <div class="user" @click="quit">
        &nbsp;&nbsp;{{ user.username }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{
          user.phone
        }}
      </div>
    </div>
    <div class="big_bottom fcc">
      <!-- 版心区域 -->
      <div class="area-center">
        <!-- 下拉框区域 -->
        <van-dropdown-menu
          v-model="showMenu"
          active-color="#1989fa"
          swipe-threshold
        >
          <van-dropdown-item
            v-model="value1"
            :title="title"
            :options="option1"
            @change="handle"
          >
          </van-dropdown-item>

          <van-dropdown-item
            v-model="value2"
            :title="title1"
            :options="option2"
            @change="handleChange"
          >
          </van-dropdown-item>
        </van-dropdown-menu>
        <!-- 计划管理区域 -->
        <TequipMent></TequipMent>
        <!-- 动火方案区域 -->
        <Programme></Programme>
      </div>
    </div>
  </div>
</template>

<script >
import TequipMent from "@/components/home/tequip/TequipMent.vue";
import Programme from "@/components/home/programme/PrograMme.vue";
import { getInfo } from "@/api/login";
import { enterpriseuser, project } from "@/api/select";
export default {
  data() {
    return {
      value1: 0,
      value2: "a",
      title: "", //企业名称
      title1: "", //项目名称
      option1: [], //企业名称
      option2: [], //企业项目,
      projectID: "", //项目id
      userId: localStorage.getItem("userId"),
      userToken: localStorage.getItem("authToken"),
      SpaceId: sessionStorage.getItem("SpaceId"),
      showMenu: false,
      user: "", //用户信息
    };
  },
  components: {
    TequipMent,
    Programme,
  },
  created() {
    this.getUser();
    this.enterprise();
    this.EnterpriseProjects();
  },
  methods: {
    //企业名称
    handle(value) {
      this.title = value;
      console.log("value", value);
    },
    //企业项目
    handleChange(value) {
      this.title1 = value;

      console.log(value.spaceId, "value.spaceIds");
    },
    //获取用户信息
    getUser() {
      getInfo(this.userId).then((res) => {
        if (res.data._rd == true) {
          this.user = res.data.result;
          sessionStorage.setItem("eID", res.data.result.eid);
        }
      });
    },
    //获取企业名称
    enterprise() {
      let params = {
        d: {
          page: {
            p: 1,
            ps: 10,
          },
          filters: [
            {
              field: "st",
              operator: "NE",
              value: 9,
            },
          ],
        },
      };
      enterpriseuser(params).then((res) => {
        if (res.data._rd == true) {
          res.data.result.forEach((item) => {
            item.text = item.name;
            item.value = item.name;
            console.log("item.spaceId", item.spaceId);
          });
          this.option1 = res.data.result;
          this.title = res.data.result[0].name;
          // console.log(res.data.result[0].spaceId);
          sessionStorage.setItem("enterprise", res.data.result[0].spaceId);
        }
      });
    },
    //获取企业项目
    EnterpriseProjects() {
      let params = {
        d: {
          c: [
            { key: "SpaceId", value: this.SpaceId },
            // { key: "userId", value: this.userId },
            // { key: "authToken", value: this.userToken },
          ],
          filters: [
            {
              field: "st",
              operator: "NE",
              value: 9,
            },
          ],
        },
      };
      project(params).then((res) => {
        res.data.result.forEach((item) => {
          item.text = item.name;
          item.value = item.name;
        });
        this.option2 = res.data.result;
        this.title1 = res.data.result[0].name;
        sessionStorage.setItem("projectspaceId", res.data.result[0].spaceId);
      });
    },
    handelChange(value) {
      // this.title = this.option[value - 1].name;
      console.log(value, value);
      console.log("111", 111111);
    },
    //退出登录
    quit() {
      if (this.user.username != undefined && this.user.phone != undefined) {
        this.$router.push({
          path: "/quit",
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.big-box {
  width: 100%;
  min-height: 6rem;

  .big_top {
    width: 100%;
    height: 2rem;
    background: url(../../assets/mipmap-xhdpi/home_top_bg.png);
    background-size: 100% 2rem;
    position: relative;
    .user {
      font-size: 0.18rem;
      position: absolute;
      bottom: 0.1rem;
      left: 0.2rem;
      color: white;
    }
  }
  .big_bottom {
    width: 100%;
    background-color: #f3f4f8;
    // 版心区域
    .area-center {
      min-height: 4rem;
      // 下拉框
    }
  }
}
</style>
